package com.ruitu.health.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.util.ScreenUtils;
import com.ruitu.arad.util.SizeUtils;
import com.ruitu.health.R;
import com.ruitu.router_module.bean.home.HomeAd;
import com.ruitu.router_module.bean.home.HomeModel;

import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class ModelAdapter extends ListBaseAdapter<HomeModel> {
    public ModelAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.app_item_home_model;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        TextView tv_name = holder.getView(R.id.tv_name);
        RecyclerView rcv_pro = holder.getView(R.id.rcv_pro);

        HomeModel model = mDataList.get(position);
        List<HomeAd> adList = model.getAdList();

        tv_name.setText(model.getName());

        HomeAdapter adapter = new HomeAdapter(mContext);
        GridLayoutManager gridManager = new GridLayoutManager(mContext, 2);
        rcv_pro.setLayoutManager(gridManager);
        rcv_pro.setAdapter(adapter);
        adapter.setDataList(adList);
    }

    private class HomeAdapter extends ListBaseAdapter<HomeAd> {

        public HomeAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.app_item_home_model_ad;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            ImageView icon = holder.getView(R.id.icon);// 商品广告的图片

            int width = ScreenUtils.getScreenWidth();
            int itemWidth = (width - SizeUtils.dp2px(30)) / 2;

            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) icon.getLayoutParams();
            params.width = itemWidth;
            params.height = itemWidth * 10 / 16;
            icon.setLayoutParams(params);
        }
    }
}
